package sliver.action.shop;

import java.io.Serializable;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import sliver.entity.Shopper;
import sliver.service.shop.machine.MachineMaintainService;

import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Controller("shop.addMachineAction")
public class AddMachineAction extends ActionSupport implements SessionAware{

	private static final long serialVersionUID = 1733747298976639564L;
	
	private String name;
	private Long oneYuanNum;
	private Long fiveYuanNum;
	private Long tenYuanNum;
	private Long twentyYuanNum;
	private Long fiftyYuanNum;
	
	private Map<String, Object> session;
	
	@Autowired
	private MachineMaintainService machineMaintainService;
	
	public AddMachineAction(){
		
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getOneYuanNum() {
		return oneYuanNum;
	}

	public void setOneYuanNum(Long oneYuanNum) {
		this.oneYuanNum = oneYuanNum;
	}

	public Long getFiveYuanNum() {
		return fiveYuanNum;
	}

	public void setFiveYuanNum(Long fiveYuanNum) {
		this.fiveYuanNum = fiveYuanNum;
	}

	public Long getTenYuanNum() {
		return tenYuanNum;
	}

	public void setTenYuanNum(Long tenYuanNum) {
		this.tenYuanNum = tenYuanNum;
	}

	public Long getTwentyYuanNum() {
		return twentyYuanNum;
	}

	public void setTwentyYuanNum(Long twentyYuanNum) {
		this.twentyYuanNum = twentyYuanNum;
	}

	public Long getFiftyYuanNum() {
		return fiftyYuanNum;
	}

	public void setFiftyYuanNum(Long fiftyYuanNum) {
		this.fiftyYuanNum = fiftyYuanNum;
	}
	
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	@Override
	public String execute() throws Exception {
		
		Shopper shopper = Shopper.class.cast(session.get("login_shopper"));
		
		Serializable id = machineMaintainService.addMachie(
													name, 
													oneYuanNum, 
													fiveYuanNum, 
													tenYuanNum, 
													twentyYuanNum, 
													fiftyYuanNum, 
													shopper.getId());
		if(id == null)
			return ERROR;
		
		return SUCCESS;
	}
}
